﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Prism.Modularity;
using Com.JJ1369.Shell.View;
using System.ComponentModel.Composition.Hosting;
using Com.JJ1369.Infrastructure.Logger;
using Com.JJ1369.Infrastructure.Behavior;
using Com.JJ1369.Infrastructure;

namespace Com.JJ1369.Shell
{
    /// <summary>
    /// using mef IOC container, so inherit from MefBootstrapper
    /// </summary>
    public partial class Bootstrapper : MefBootstrapper
    {
        /// <summary>
        /// Config Aggregate Catalogs.
        /// </summary>
        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellView).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(RegionName).Assembly));
        }

        /// <summary>
        /// Initializae Root View.
        /// </summary>
        protected override void InitializeShell()
        {
            base.InitializeShell();
            Application.Current.RootVisual = this.Shell as UIElement;
        }

        /// <summary>
        /// Create ModuleCatalog from config file.
        /// </summary>
        /// <returns></returns>
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri(
            "/Com.JJ1369.Shell;component/ModuleCatalog.xaml",
            UriKind.Relative));
        }

        /// <summary>
        /// Create Root View
        /// </summary>
        /// <returns>Root View</returns>
        protected override DependencyObject CreateShell()
        {
            return this.Container.GetExportedValue<ShellView>();
        }

        /// <summary>
        /// Create your own logger.
        /// </summary>
        /// <returns>your own logger</returns>
        protected override Microsoft.Practices.Prism.Logging.ILoggerFacade CreateLogger()
        {
            return DebugAdapter.Instance;
        }

        /// <summary>
        /// Add global resources here.
        /// </summary>
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
        }


        protected override Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
        {
            var factory = base.ConfigureDefaultRegionBehaviors();
            factory.AddIfMissing("AutoPopulateExportedViewBehavior", typeof(AutoPopulateExportedViewBehavior));
            return factory;
        }
    }
}
